package pl.edu.pw.perg.compinfodb.datamodel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

import pl.edu.pw.perg.compinfodb.entities.ElementType;
import pl.edu.pw.perg.compinfodb.manager.IElementTypeManager;

public class TypeComboModel implements ComboBoxModel{

  private IElementTypeManager typeManager;
  private List<ElementType> types;
  private ElementType selected;

  private List<ListDataListener> listeners = new LinkedList<ListDataListener>();
  private List<ActionListener> actionListeners = new LinkedList<ActionListener>();
  
  public TypeComboModel(IElementTypeManager manager) {
    this.typeManager = manager;
    types = manager.findAll();

  }

  public void actionPerformed(ActionEvent e) {
    for (ActionListener l : actionListeners) {
      l.actionPerformed(e);
    }
  }

  public void addActionListener(ActionListener l){
    actionListeners.add(l);
  }
  
  public void removeActionListener(ActionListener l){
    actionListeners.remove(l);
  }
  public ElementType getSelectedItem() {
    return selected;
  }
  
  public void setSelectedItem(Object arg0) {
    selected = (ElementType) arg0;
    
  }

  public void addListDataListener(ListDataListener arg0) {
    listeners.add(arg0);
    
  }

  public Object getElementAt(int arg0) {
    return types.get(arg0);
  }

  public int getSize() {
    return types.size();
  }

  public void removeListDataListener(ListDataListener arg0) {
    listeners.remove(arg0);    
  }

}
